package com.uwantsoft.interfaces.web.controller.web;

import com.uwantsoft.business.facade.DriverFacadeImpl;
import com.uwantsoft.business.facade.dto.user.DriverDetailDto;
import com.uwantsoft.business.facade.dto.user.DriverOverviewQueryCondition;
import com.uwantsoft.util.PerformanceChecker;
import com.uwantsoft.util.paging.DefaultPaginatedList;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @author Chuanbao
 */
@Controller
@RequestMapping(value = "/backend")
public class DriverManagementController {

    @Resource(name = "driverFacade")
    private DriverFacadeImpl driverFacade;

    @RequestMapping(value = "driversoverview")
    public String driversOverview(DriverOverviewQueryCondition condition,Model model){
        DefaultPaginatedList paging = driverFacade.obtainDrivers(condition);
        model.addAttribute("paging", paging);
        return "backend/driversoverview";
    }

    @RequestMapping(value = "lockdriver")
    public String lockDriver(String guid,boolean lock,DriverOverviewQueryCondition condition,Model model){
        driverFacade.lockDriver(guid, lock);
        model.addAttribute("username",condition.getUsername());
        model.addAttribute("page",condition.getPage());
        return "redirect:driversoverview";
    }

    @RequestMapping(value = "driverdetails")
    public String driverDetails(String guid,Model model){
        DriverDetailDto driverDetailDto = driverFacade.obtainDriver(guid);
        model.addAttribute("driver",driverDetailDto);
        return "backend/driverdetails";
    }
}
